import  sys
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
global sec
sec=0

class WorkThread(QThread):
    trigger=pyqtSignal()
    def __init__(self):
        super(WorkThread,self).__init__()
    def run(self):
        for i in  range(300000000):
            pass
        self.trigger.emit()#循环完毕发射信号
def  countTime():
    global sec
    sec +=1
    lcdNmber.display(sec)
def work():
    #计时器计数
    timer.start(1000)
    workThread.start()
    #获得循环完毕停止计数
    workThread.trigger.connect(timeStop)
def timeStop():
    timer.stop()
    print("结束用时",lcdNmber.value())
    global sec
    sec=0

if __name__ == '__main__':
    app=QApplication(sys.argv)
    top=QWidget()
    top.resize(300,150)
    layout=QVBoxLayout(top)
    #显示面板
    lcdNmber=QLCDNumber()
    layout.addWidget(lcdNmber)
    button=QPushButton("测试")
    layout.addWidget(button)
    timer=QTimer()
    workThread=WorkThread()
    button.clicked.connect(work)
    #每次计数结束 出发 countTime
    timer.timeout.connect(countTime)


    top.show()
    sys.exit(app.exec_())
